﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyDBconnection;

namespace CamposInventory
{
    public partial class frmManagestock : Form
    {
        FrmMain parent;
        DatabaseConnection dbconn = new DatabaseConnection();
       
        public frmManagestock(FrmMain p)
        {
            InitializeComponent();
            parent = p;
            this.Load += new EventHandler(frmProdcutlist_Load);
            txtsearch.Click += new EventHandler(txtsearch_Click);
            txtsearch.TextChanged += new EventHandler(txtsearch_TextChanged);
            btnnew.Click += new EventHandler(btnnew_Click);
            btnManagestock.Click += new EventHandler(btnManagestock_Click);

           
        }

        void btnManagestock_Click(object sender, EventArgs e)
        {
            frmStock frmstock = new frmStock();
            frmstock.Show();
        }

        void btnnew_Click(object sender, EventArgs e)
        {
            frmAddproduct frmadd = new frmAddproduct();
            frmadd.Show();
        }

        void txtsearch_TextChanged(object sender, EventArgs e)
        {
            if (txtsearch.Text != "")
            {
                DataView dw = new DataView(dbconn.tbl);
                dw.RowFilter = string.Format("ProductCode LIKE '%{0}'", txtsearch.Text);
                dataGridView1.DataSource = dw;
            }
            else
            {
                dbconn.dbconnection();
                dbconn.loadData("Select * from tblstockinout");
                dbconn.DBClose();
            
            }
           
        }

       

        void txtsearch_Click(object sender, EventArgs e)
        {
            txtsearch.Text = "";
        }
      
        void frmProdcutlist_Load(object sender, EventArgs e)
        {
            dbconn.dbconnection();
            dbconn.loadproduct("Select *  from tblstockinout");
            dataGridView1.DataSource = dbconn.tbl;
            dbconn.DBClose();
            
        }
    }
}
